<?php

class DefaultController extends Controller
{
	public function actionIndex()
	{
		$this->render('index');
	}

	public function actionLogin(){
		Yii::app()->language = "vn";
		$this->layout = "//layouts/login";
		$model = new LoginForm;
		$model->scenario = "admin";
		// collect user input data
		$this->validateAjax($model);
		if(isset($_POST['LoginForm'])){
			$model->attributes=$_POST['LoginForm'];
			// validate user input and redirect to the previous page if valid
			if($model->validate() && $model->login()){
				Yii::app()->user->setState('isAdmin', true) ;
				$this->redirect(Yii::app()->createUrl('admin'));
			}
		}
		$this->render("login", array('model'  => $model));
	}

	public function actionLogout(){
		Yii::app()->user->logout();
		$this->redirect(Yii::app()->createUrl('admin/login.html'));
	}
}